﻿using SCADA_SANEST.Models;
using SCADA_SANEST.Models.Line_1;
using SCADA_SANEST.Models.Line_2;
using SCADA_SANEST.Services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SCADA_SANEST.ViewModels.Shares
{
    public class PlcDataDetailViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<PlcSignal> Signals { get; set; }

        private PlcDeviceStatus _device;

        public PlcDataDetailViewModel(PlcDeviceStatus device)
        {
            _device = device;

            // Lấy Signals từ service đang chạy
            PlcBaseService service = null;
            switch (device.Type)
            {
                case DeviceType.Npc1:
                    service = ServiceManager.GetService("NPC1");
                    break;
                case DeviceType.Npc2:
                    service = ServiceManager.GetService("NPC2");
                    break;
                case DeviceType.Hsl3:
                    service = ServiceManager.GetService("HSL3");
                    break;
                case DeviceType.Hbt4:
                    service = ServiceManager.GetService("HBT4");
                    break;
            }

            Signals = service != null ? service.Signals : new ObservableCollection<PlcSignal>();

            // Khởi động polling chỉ khi service chưa chạy polling riêng (optional)
            // StartReading(); // không cần thiết nếu Signals đã đang được service cập nhật
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}